﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace EClinic.pathwaysView
{
    public class Relation
    {
        public static Point TempStartpoint = new Point();
        public static Point TempEndpoint = new Point();
    }
        public class Position : IXmlSerializable
        {
            public Position()
            {
                X = 0;
                Y = 0;
            }
            public int X { get; set; }
            public int Y { get; set; }

            public XmlSchema GetSchema()
            {
                return null;
            }

            public void ReadXml(XmlReader reader)
            {

                this.X = Convert.ToInt32(reader.GetAttribute("X"));
                this.Y = Convert.ToInt32(reader.GetAttribute("Y"));
            }

            public void WriteXml(XmlWriter writer)
            {
                writer.WriteStartElement("position");
                writer.WriteAttributeString("X", this.X.ToString());
                writer.WriteAttributeString("Y", this.Y.ToString());
                writer.WriteEndElement();
            }
        }

        public class StartNode : IXmlSerializable
        {

            public StartNode()
            {
                Pos = new Position();

            }
            public Position Pos { get; set; }
           public void Draw(PathWayDrawing DrawingSpace)
            {
                DrawingSpace.DrawNode(new Point(Pos.X, Pos.Y), PathWayNodesTybes.StartNode);
                NextNode.Draw(DrawingSpace);
            }

            public INode NextNode { get; set; }
            public XmlSchema GetSchema()
            {
                return null;
            }

            public void ReadXml(XmlReader reader)
            {
                throw new NotImplementedException();
            }

            public void WriteXml(XmlWriter writer)
            {
                writer.WriteStartElement("StartNode");
                Pos.WriteXml(writer);
                NextNode.WriteXml(writer);
                writer.WriteEndElement();

            }
        }

        public interface INode : IXmlSerializable
        {
            Position Pos { get; set; }
            void Draw(PathWayDrawing DrawingSpace);
            void Run();

        }



        public class YesNoNode : INode
        {
            public YesNoNode()
            {
                Pos = new Position();
                Prompt = "";
            }
            public string Prompt { get; set; }

            public Position Pos { get; set; }
            public void Draw(PathWayDrawing DrawingSpace)
            {
                DrawingSpace.DrawNode(new Point(Pos.X, Pos.Y), PathWayNodesTybes.YesOrNoQNode);
                YesNode.Draw(DrawingSpace);
                NoNode.Draw(DrawingSpace);
            }

            public void Run()
            {
                Console.WriteLine(Prompt);
                string temp = Console.ReadLine();
                if (temp == "yes")
                {
                    YesNode.Run();
                }
                else if (temp == "no")
                {
                    NoNode.Run();
                }
                else
                {
                    Run();
                    return;
                }


            }

            public INode YesNode { get; set; }

            public INode NoNode { get; set; }

            public XmlSchema GetSchema()
            {
                return null;
            }

            public void ReadXml(XmlReader reader)
            {
                throw new NotImplementedException();
            }

            public void WriteXml(XmlWriter writer)
            {
                writer.WriteStartElement("YesNoNode");
                writer.WriteAttributeString("Prompt", this.Prompt.ToString());
                Pos.WriteXml(writer);
                YesNode.WriteXml(writer);
                NoNode.WriteXml(writer);
                writer.WriteEndElement();
            }
        }

        public class ActivtyNode : INode
        {

            public ActivtyNode()
            {
                Pos = new Position();
                Prompt = "";
            }
            public string Prompt { get; set; }



            public Position Pos
            {
                get;
                set;
            }

             public void Draw(PathWayDrawing DrawingSpace)
            {
                DrawingSpace.DrawNode(new Point(Pos.X, Pos.Y), PathWayNodesTybes.ActivityNode);
                NextNode.Draw(DrawingSpace);
               
            }

            public void Run()
            {
                Console.WriteLine(Prompt);
                NextNode.Run();
            }

            public INode NextNode { get; set; }

            public XmlSchema GetSchema()
            {
                return null;
            }

            public void ReadXml(XmlReader reader)
            {
                throw new NotImplementedException();
            }

            public void WriteXml(XmlWriter writer)
            {
                writer.WriteStartElement("ActivtyNode");
                writer.WriteAttributeString("Prompt", this.Prompt.ToString());
                Pos.WriteXml(writer);
                NextNode.WriteXml(writer);
                writer.WriteEndElement();
            }
        }

        public class PathWayNode : INode
        {
            public PathWayNode()
            {
                Pos = new Position();
                Prompt = "";
            }

            public string Prompt { get; set; }


            public Position Pos
            {
                get;
                set;
            }

            public void Draw(PathWayDrawing DrawingSpace)
            {
                DrawingSpace.DrawNode(new Point(Pos.X, Pos.Y), PathWayNodesTybes.PathWayNode);
            }

            public void Run()
            {
                SubPathWay.Run();
            }

            public PathWay SubPathWay { get; set; }
            public XmlSchema GetSchema()
            {
                return null;
            }

            public void ReadXml(XmlReader reader)
            {
                throw new NotImplementedException();
            }

            public void WriteXml(XmlWriter writer)
            {
                writer.WriteStartElement("PathWayNode");
                writer.WriteAttributeString("Prompt", this.Prompt.ToString());
                Pos.WriteXml(writer);
                SubPathWay.WriteXml(writer);
                writer.WriteEndElement();
            }
        }

        public class EndNode : INode
        {
            public EndNode()
            {
                Pos = new Position();
            }


            public Position Pos
            {
                get;
                set;
            }

            public void Draw(PathWayDrawing DrawingSpace)
            {
                DrawingSpace.DrawNode(new Point(Pos.X, Pos.Y), PathWayNodesTybes.EndNode);
            }

            public void Run()
            {

                throw new NotImplementedException();
            }

            public XmlSchema GetSchema()
            {
                return null;
            }

            public void ReadXml(XmlReader reader)
            {
                throw new NotImplementedException();
            }

            public void WriteXml(XmlWriter writer)
            {

                writer.WriteStartElement("EndNode");
                Pos.WriteXml(writer);
                writer.WriteEndElement();
            }
        }

        public class PathWay : IXmlSerializable
        {

            public StartNode Start { get; set; }

            public void Draw(PathWayDrawing DrawingSpace)
            {
              Start.Draw(DrawingSpace);
            }

            public void Run()
            {
                Console.WriteLine("pathway started");
                Start.NextNode.Run();

            }

            public XmlSchema GetSchema()
            {
                return null;
            }

            public void ReadXml(XmlReader reader)
            {
                throw new NotImplementedException();
            }

            public void WriteXml(XmlWriter writer)
            {
                Start.WriteXml(writer);
            }
        }   
    
}
